<?php
   function N_Model($value){  //  实例化模型
    $new_path ="model/".$value."Model.class.php";
    require_once($new_path);
    $new_name = $value."Model";
   	$new_cls = new $new_name();
   	return $new_cls;
   }
   
   function N_Action($M,$C,$A){  //组合控制器路径
   	$path = "action/".$M."/".$C."Action.class.php";
   	require_once ("$path");
    $path_name = $C."Action";
    $cls = new $path_name();
    return $cls;
   }
   
   function Is_default($val,$num=1){   //给index赋初值
   	if($num==1)
   	{
   		if(!empty($val))
   		{
   			return $val;
   		}
   		$val = "index";
   		return $val;
   	}

   	if($num ==2)
   	{
   	    if(!empty($val))
   		{
   			return $val;
   		}
   		$val = "user";
   		return $val;
   		
   	}   	
   	if($num == 3)
   	{
   		if(!empty($val))
   		{
   			return $val;
   		}
   		$val = "login";
   		return $val;
   	}
   }
   
   
  //引入模板函数 
   function display($value="")
   {
   	 global $M,$C,$A;
   	 if($value !="")
   	 {return $value;}
   	 $path = "tpl/".$M."/".$C."/".$A.".tpl.php";
   	 return  $path;
   	 
   }
   
   //字符串验证
  function strgpc($value)
  {
    if(is_array($value)){ echo "异常"; exit;}
  	if(!get_magic_quotes_gpc())
  	{
  		$value = addslashes($value);
  		return $value;
  	}
  	return  $value;
  
  }
  
  //验证登录
   function checklogin($value)
   {
   	 if(empty($value))
   	 {
   	 	echo "<script language='javascript'>alert(' FUCK, not login~~!')</script>";
 	    echo "<script language='javascript'>window.location.href='?'</script>";
 	    exit;
   	 }
   }
   
   //用户登录
   function adminlogin($value)
   {
    if($value != 1)
   	 {
   	 	echo "<script language='javascript'>alert(' FUCK, not admin~~!')</script>";
 	    echo "<script language='javascript'>window.location.href='?'</script>";
 	    exit;
   	 }
   }
   
   //检查传入值
  function checkstr($value,$num)
  {
  	if($num == 1)
  	{
  		return  ereg("^[0-9A-Za-z_]{6,8}$",$value);
  	}
  	if($num == 2)
  	{
  		
  		return eregi("^[_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3}$",$value);
  	}
  	
  }
  
  // 出错跳转页面
  function error()
  {
  	return "tpl/index/index/error.tpl.php";
  }
  
  	/*扩展函数*/
	 
	/**
	 * 返回经addslashes处理过的字符串或数组
	 * @param $string 需要处理的字符串或数组
	 * @return mixed
	 */
	function new_addslashes($string){
		if(!is_array($string)) return addslashes($string);
		foreach($string as $key => $val) $string[$key] = new_addslashes($val);
		return $string;
	}
	
	/**
	 * 返回经stripslashes处理过的字符串或数组
	 * @param $string 需要处理的字符串或数组
	 * @return mixed
	 */
	function new_stripslashes($string) {
		if(!is_array($string)) return stripslashes($string);
		foreach($string as $key => $val) $string[$key] = new_stripslashes($val);
		return $string;
	}
	
	/**
	 * 返回经htmlspecialchars处理过的字符串或数组
	 * @param $obj 需要处理的字符串或数组
	 * @return mixed
	 */
	function new_html_special_chars($string) {
		if(!is_array($string)) return htmlspecialchars($string);
		foreach($string as $key => $val) $string[$key] = new_html_special_chars($val);
		return $string;
	}
	/**
	 * 安全过滤函数
	 *
	 * @param $string
	 * @return string
	 */
	function safe_replace($string) {
		$string = str_replace('%20','',$string);
		$string = str_replace('%27','',$string);
		$string = str_replace('%2527','',$string);
		$string = str_replace('*','',$string);
		$string = str_replace('"','&quot;',$string);
		$string = str_replace("'",'',$string);
		$string = str_replace('"','',$string);
		$string = str_replace(';','',$string);
		$string = str_replace('<','&lt;',$string);
		$string = str_replace('>','&gt;',$string);
		$string = str_replace("{",'',$string);
		$string = str_replace('}','',$string);
		$string = str_replace('\\','',$string);
		return $string;
	}
	  
	  
	  
  
  
  
?>